package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.bean.BaseRecordBean;
import com.zhongjian.technologycal.mall.bean.PresenterOverBean;

import java.util.List;

/**
 * Created by wei on 2018/1/29.
 */

public class CrashRecordAdapter extends BaseAdapter {

    private Context context;
    private List<BaseRecordBean> listItems;
    private LayoutInflater listContainer;

    public final class ViewHolder {
        public TextView record_tv_title;
        public TextView record_tv_money;
        public TextView record_tv_time;

    }

    public CrashRecordAdapter(Context context, List<BaseRecordBean> listItems) {
        this.context = context;
        listContainer = LayoutInflater.from(context);
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        CrashRecordAdapter.ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new CrashRecordAdapter.ViewHolder();
            convertView = listContainer.inflate(R.layout.items_crash_record,
                    null);
            viewHolder.record_tv_title = (TextView) convertView
                    .findViewById(R.id.record_tv_title);
            viewHolder.record_tv_money = (TextView) convertView
                    .findViewById(R.id.record_tv_money);
            viewHolder.record_tv_time = (TextView) convertView
                    .findViewById(R.id.record_tv_time);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CrashRecordAdapter.ViewHolder) convertView.getTag();
        }

        //将数据填充到具体的view中
        viewHolder.record_tv_title.setText("" + listItems.get(position).getData().get(position).getMemo());
        if (listItems.get(position).getData().get(position).getAddSub().equals("+")) {
            viewHolder.record_tv_money.setText(listItems.get(position).getData().get(position).getAddSub() + " " +
                    listItems.get(position).getData().get(position).getAmount());
            viewHolder.record_tv_money.setTextColor(context.getResources().getColor(R.color.blue));
        } else if (listItems.get(position).getData().get(position).getAddSub().equals("-")) {
            viewHolder.record_tv_money.setText(listItems.get(position).getData().get(position).getAddSub() + " " +
                    listItems.get(position).getData().get(position).getAmount());

        }

        viewHolder.record_tv_time.setText("" + listItems.get(position).getData().get(position).getCreateTime());


        return convertView;
    }
}
